<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ page import="com.scalar.chiptrack.utils.ConfigManager" %>
<%@ page import="com.scalar.chiptrack.commons.Constants" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.GregorianCalendar" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/vendorShipmentReport.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>
<%
    String userTypeChiptrac = Constants.USER_TYPE_CHIPTRAC + "";
    String userTypeCustomer = Constants.USER_TYPE_CUSTOMER + "";
    String userTypeSalesPerson = Constants.USER_TYPE_SALES_PERSON + "";
%>
<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>
</HEAD>
<script language="javascript">

    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }

    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }

    function validateFromAndToDates()
    {
        formdoc = document.revenueShipmentReportForm;
        errMsg = '';

        var pa	= document.getElementById("errors")

        if(chkDate(formdoc.fromDate.value,'From-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.fromDate.focus();
            return false;
        }

        if(chkDate(formdoc.toDate.value,'To-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.toDate.focus();
            return false;
        }

        if(formdoc.fromDate.value!='' && formdoc.toDate.value!='')
        {
            if (!validateDateOut(formatDateAsMMDDYYYY(formdoc.fromDate.value),formatDateAsMMDDYYYY(formdoc.toDate.value)))
            {
                pa.innerHTML = "To Date cannot be less than From Date";
                formdoc.toDate.focus();
                return false;
            }
        }
        return true;
    }
    function submitReport( fileType )
    {
        var d = new Date();
        var day = d.getDate();
        var month = d.getMonth()+1;
        var year = d.getFullYear();
        var hour = d.getHours();
        var min = d.getMinutes();
        var sec = d.getSeconds();
        var pa	= document.getElementById("errors")
        var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;
        var success;
        var formdoc = document.revenueShipmentReportForm

        success = true;
        success = validateFromAndToDates();
        if( success == false )
        {
            return;
        }

        var partNumberObj = formdoc.customer;
        var processstepId = "";
        var count = 0;
        for( var i = 0; i < partNumberObj.length; i++ )
        {
            if( partNumberObj.options[i].selected )
            {
                count++;
                if ( processstepId != '' )
                {
                    processstepId = processstepId + "," + partNumberObj.options[i].value;
                }
                else
                {
                    processstepId = partNumberObj.options[i].value;
                    if( partNumberObj.options[i].value == '0' )
                    {
                        break;
                    }
                }
            }
        }
        if ( processstepId == '')
        {
            processstepId = "0";
        }
        if( count > 10)
        {
            pa.innerHTML = "<li>Please select upto 10 Customers only";
            return;
        }
        else
        {
            formdoc.prompt0.value = processstepId;
        }
       
        <%--<logic:equal value="<%=userTypeCustomer%>" name="user" property="userType" scope="session">
        if  ( formdoc.prompt0.value== 0 )
        {
            var element = formdoc.customer;
            var customerIds = "";
            for( var i = 0 ; i < element.length; i++ )
            {
                if ( customerIds != '' && customerIds != "0" )
                {
                    customerIds = customerIds+","+element.options[i].value;
                }
                else
                {
                    customerIds = element.options[i].value;
                }
            }

            formdoc.prompt0.value= customerIds;
        }
        </logic:equal>--%>

        <logic:equal value="<%=userTypeSalesPerson%>" name="user" property="userType" scope="session">
        if  ( formdoc.prompt0.value== 0 )
        {
            var element = formdoc.customer;
            var customerIds = "0";
            for( var i = 0 ; i < element.length; i++ )
            {
                if ( customerIds != '' && customerIds != "0" )
                {
                    customerIds = customerIds+","+element.options[i].value;
                }
                else
                {
                    customerIds = element.options[i].value;
                }
            }

            formdoc.prompt0.value= customerIds;
        }
        </logic:equal>

        if ( formdoc.vendorName.value == '' )
        {
            formdoc.prompt1.value = '0';
        }
        else
        {
            formdoc.prompt1.value = formdoc.vendorName.value;
        }

        if ( formdoc.soNumber.value == '' )
        {
            formdoc.prompt3.value = '0';
        }
        else
        {
            formdoc.prompt3.value = formdoc.soNumber.value;
        }

        if ( formdoc.endCustomer.value == '' )
        {
            formdoc.prompt2.value = '0';
        }
        else
        {
            formdoc.prompt2.value = formdoc.endCustomer.value;
        }
        <logic:equal value="<%=userTypeCustomer%>" name="user" property="userType" scope="session">
        if  ( formdoc.prompt2.value== 0 )
        {
            var element = formdoc.endCustomer;
            var customerIds = "0";
            for( var i = 0 ; i < element.length; i++ )
            {
                if ( customerIds != '' && customerIds != "0" )
                {
                    customerIds = customerIds+","+element.options[i].value;
                }
                else
                {
                    customerIds = element.options[i].value;
                }
            }

            formdoc.prompt2.value= customerIds;
        }
        </logic:equal>

        <logic:equal value="<%=userTypeSalesPerson%>" name="user" property="userType" scope="session">
        if  ( formdoc.prompt2.value== 0 )
        {
            var element = formdoc.endCustomer;
            var customerIds = "0";
            for( var i = 0 ; i < element.length; i++ )
            {
                if ( customerIds != '' && customerIds != "0" )
                {
                    customerIds = customerIds+","+element.options[i].value;
                }
                else
                {
                    customerIds = element.options[i].value;
                }
            }

            formdoc.prompt2.value= customerIds;
        }
        </logic:equal>

        formdoc.prompt5.value = formdoc.category.value;
        formdoc.prompt4.value = '';

        if ( formdoc.fromDate.value == '' )
        {
            formdoc.prompt6.value = '0';
        }
        else
        {
            formdoc.prompt6.value = formdoc.fromDate.value;
        }
        if ( formdoc.toDate.value == '' )
        {
            formdoc.prompt7.value = '0';
        }
        else
        {
            formdoc.prompt7.value = formdoc.toDate.value;
        }
        formdoc.prompt8.value = 'crystal';
        formdoc.prompt9.value = defaultPrompt;
        formdoc.prompt10.value = '';

        if( fileType == 2 )
        {
            var prompt0 = formdoc.prompt0.value;
            var prompt1 = formdoc.prompt1.value;
            var prompt2 = formdoc.prompt2.value;
            var prompt3 = formdoc.prompt3.value;
            var prompt4 = formdoc.prompt4.value;
            var prompt5 = formdoc.prompt5.value;
            var prompt6 = formdoc.prompt6.value;
            var prompt7 = formdoc.prompt7.value;
            var prompt8 = "xlreport"; // for report type prompt
            var prompt9 = formdoc.prompt9.value; // for default prompt

            var newWindow;
            var url = '<%=chipTracContext%>/vendorShipmentReport.do?action=generateVendorShipmentXls&popUp=true&prompt0=' + prompt0 + '&prompt1=' + prompt1 + '&prompt2=' + prompt2 + '&prompt3=' + prompt3 + '&prompt4=' + prompt4 + '&prompt5=' + prompt5 + '&prompt6=' + prompt6 + '&prompt7=' + prompt7 + '&prompt8=' + prompt8 + '&prompt9=' + prompt9;
            newWindow = window.open ( url, 'VendorShipmentReport', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=450,height=150,resizable=yes');
        }
        else
        {
            formdoc.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Sales/Shipped/Vendor_Shipment_Report.rpt";
            formdoc.submit();
            return true;
        }
    }
    function initLoad(){
        <%!
          String fromDate = null;
          String toDate = null;
        %>
        <%

            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
            Calendar calendar = Calendar.getInstance();
            GregorianCalendar gc = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
            gc.add(GregorianCalendar.YEAR, -1);
            Date d = gc.getTime();
            fromDate = sdf.format(d);

            SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy");
            Calendar calendar1 = Calendar.getInstance();
            GregorianCalendar gc1 = new GregorianCalendar(calendar1.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
            gc1.add(GregorianCalendar.DATE, 1);
            Date d1 = gc1.getTime();
            toDate = sdf1.format(d1);
        %>
        document.getElementById("fromdate").value = "<%=fromDate%>";
        document.getElementById("todate").value = "<%=toDate%>";
    }
</script>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="initLoad();">
<!-- Top Header Start-->
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/header.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/extHeader.jsp" %>
    </logic:notEqual>
<!-- Top Header End-->
<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
    <!-- Side Navigation start -->
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/sales/sales_report_menu.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/sales/external_reports_menu.jsp" %>
    </logic:notEqual>
    <!-- end of the side navigations -->
    </TD>
    <TD bgcolor="#ffffff">
        <IMG height="9" src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="2"></TD>
        <TD valign="top" width="100%">
        <IMG height="1" src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width="500" border="0">
        <BR>
        <html:form name="revenueShipmentReportForm" type="com.scalar.chiptrack.sales.reports.forms.RevenueShipmentReportForm" action="/vendorShipmentReport">
        <TABLE border="0" width="100%" align="center">
            <TR><TD colspan="7" class="NArialW" align="center">Vendor Shipment Report</TD></TR>
            <TR>
                <TD colspan="6">
                    <input type="hidden" name="prompt0">
                    <input type="hidden" name="prompt1">
                    <input type="hidden" name="prompt2">
                    <input type="hidden" name="prompt3">
                    <input type="hidden" name="prompt4">
                    <input type="hidden" name="prompt5">
                    <input type="hidden" name="prompt6">
                    <input type="hidden" name="prompt7">
                    <input type="hidden" name="prompt8">
                    <input type="hidden" name="prompt9">
                    <input type="hidden" name="prompt10">
                </TD>
            </TR>
            <TR><TD colspan="6">&nbsp;</TD></TR>
            <TR><TD width="12%" >&nbsp;</TD><TD colspan="6" class='NArialL' align="left"><strong><FONT id="errors" styleClass="NArialL" color='FF0000'>&nbsp;</FONT></strong></TD></TR>
            <TR>
                <TD>&nbsp;</TD>
                <TD colspan="6" align="left">
                  <chiptrack:info styleClass="NArialL" />
                  <chiptrack:errors styleClass="NArialL" />
                  <chiptrack:messages type="info" styleClass="NArialL" />&nbsp;
                </TD>
            </TR>
            <TR>
                    <TD width="10%" >&nbsp;</TD>
                    <TD width="15%" class="NArialL" valign = 'top'>Vendor :</TD>
                    <TD width="20%" class="NArialL" valign = 'top'>
                        <html:select property="vendorName" name="revenueShipmentReportForm" styleClass="txfield" style="width:180px">
                            <html:options collection="vendorList" property="value" labelProperty="label"/>
                        </html:select>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="15%" class="NArialL" valign = 'top' align = "left">Customer :</TD>
                    <TD width="20%" class="NArialL" valign = 'top'>
                        <html:select property="customer" name="revenueShipmentReportForm" styleClass="txfield" style="width:180px" multiple="true" size="5">
                            <html:options collection="customerList" property="value" labelProperty="label"/>
                        </html:select>
                    </TD>
                    <TD width="10%">&nbsp;</TD>
                </TR>
                <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=8></TD></TR>
                <TR>
                    <TD width="10%">&nbsp;</TD>
                    <TD width="18%" class="NArialL" valign="top" align = "left" norap>Sales Order No :</TD>
                    <TD width="20%" class="NArialL">
                        <html:text property="soNumber" name="revenueShipmentReportForm" styleClass="txfield" style="width:150px"/>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="15%" class="NArialL" valign="top"><bean:message key="label.sales.shipToCustomer"/> :</TD>
                    <TD width="20%" class="NArialL">
                        <html:select property="endCustomer" name="revenueShipmentReportForm" styleClass="txfield" style="width:180px" >
                            <html:option value="0">All <bean:message key="label.sales.shipToCustomer"/>s</html:option>
                            <html:options collection="endCustomerList" property="value" labelProperty="label"/>
                        </html:select>
                    </TD>
                    <TD width="15%">&nbsp;</TD>
                </TR>
                <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=8></TD></TR>
                <TR>
                    <TD width="10%">&nbsp;</TD>
                    <TD width="15%">&nbsp;</TD>
                    <TD width="20%">&nbsp;</TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="15%" class="NArialL" valign="top" align = "left">Category :</TD>
                    <TD width="20%" class="NArialL" valign="top">
                           <html:select property="category" styleClass="txfield" style="width:180px">
                                <html:option value="1" >Regular</html:option>
                                <html:option value="0">Sample</html:option>
                           </html:select>
                    </TD>
                    <TD width="15%">&nbsp;</TD>
                </TR>
                <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=08></TD></TR>
                <TR>
                    <TD width="10%">&nbsp;</TD>
                    <TD width="15%" class="NArialL" valign="top">From Date :</TD>
                    <TD width="20%" class="NArialL">
                        <html:text property="fromDate" name="revenueShipmentReportForm" styleClass="txfield" size="12"/>
                        <a href="javascript:openCalendar(document.revenueShipmentReportForm.fromDate)">
                        <img onMouseOver="window.status='Click here to select From Date';return true" onMouseOut="window.status='';return true" border="0" align='center'  title="Click here to Select From Date"
                            src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=17 width=17></a></TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="15%" class="NArialL">To Date :</TD>
                    <TD width="20%" class="NArialL">
                        <html:text property="toDate" name="revenueShipmentReportForm" styleClass="txfield" size="12"/>
                        <a href="javascript:openCalendar(document.revenueShipmentReportForm.toDate)">
                          <img onMouseOver="window.status='Click here to select To Date';return true" onMouseOut="window.status='';return true" border="0" align='center'  title="Click here to Select To Date"
                            src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=17 width=17></a></TD>
                    <TD width="15%">&nbsp;</TD>
                </TR>
                <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></TD></TR>
                <TR>
                    <TD width="10%">&nbsp;</TD>
                    <TD width="15%">&nbsp;</TD>
                    <TD width="20%">&nbsp;</TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="15%">&nbsp;</TD>
                    <td width="20%" valign="top">
                        <a class="NArialL" href="javascript:submitReport(2)" onMouseOver="window.status='Click here to Export to Excel';return true" onMouseOut="window.status='';return true" title='Click here to Export to Excel' >Export to Excel</a>
                    </td>
                </TR>
                <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></TD></TR>
                <TR>
                    <TD colspan="6" align=center>
                        <a href="javascript:submitReport(1);"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Vendor Shipment Report';return true" onmouseout="window.status='';return true" title='Click to Generate Vendor Shipment Report'></a>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:document.revenueShipmentReportForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to reset search';return true" onmouseout="window.status='';return true" title="Click here to reset search"></a>
                    </TD>
                </TR>
                <TR><TD colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></TD></TR>
        </TABLE>
        </html:form>
    </TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>

